import { msg } from './util.js'


let BASE_URL = 'http://localhost:9005'
// let BASE_URL = 'https://6c0d-58-254-44-2.ap.ngrok.io'
// let BASE_URL = 'http://www.cyljx.xyz:9005'


const request = (options = {}) => {
	// resolve 正常响应，reject异常响应
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + options.url,
			method: options.method || 'GET',
			data: options.data || {},
			timeout: 8000, 
			success: (res) => {
				resolve(res.data)
			},
			fail: (err) => {
				msg('请求接口失败')
				reject(err)
			}
		})
	}) 
}

// 导出
export default request